package com.example.demo.controller;

import com.example.demo.entity.Shop;
import com.example.demo.impl.Objectlmpl;
import com.example.demo.impl.Shop1Impl;
import com.example.demo.impl.Shop2Impl;
import com.example.demo.impl.ShopImpl;
import com.example.demo.mapper.ShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shop")
@CrossOrigin(origins="http://localhost:8080")
public class Shopcontroller {
    @Autowired
    ShopImpl ShopImpl;
    @Autowired
    Shop1Impl ShopImpl1;
    @Autowired
    Shop2Impl ShopImpl2;

    @GetMapping("/findallshop")
    public List<Shop> getallshop()
    {
        return ShopImpl.getallshop();
    }

    @GetMapping("/addtocard")
    public void addtocard(String username,Integer shopid,Integer commodityid,Integer  number)
    {
int relaid=ShopImpl2.getid(username,shopid);
ShopImpl1.addtocard(commodityid,number,relaid);
    }

    @GetMapping("/addtocard1")
    public Integer addtocard1(String username,Integer shopid)
    {
       return ShopImpl2.getid(username, shopid);
    }
    @GetMapping("/state")
    public Object findBy_stateid(int state)
    {
        return ShopImpl.getstateidList(state);
    }

    @GetMapping("/addtocard2")
    public Integer addtocard2(Integer commodityid,Integer number,Integer relaid)
    {
        return ShopImpl1.addtocard(commodityid, number, relaid);
    }
}
